Skip to content

Add Copyright class and copyright_diff() #82 #83 - #85

Merged
steven-esser merged 7 commits into
developfrom
83-add-copyright-diff
Mar 8, 2018
Merged

Add Copyright class and copyright_diff() #82 #83#85
steven-esser merged 7 commits into
developfrom
83-add-copyright-diff

Conversation

@johnmhoran

Copy link
Copy Markdown
Member

Addresses issues #82 and #83, both of which are partial implementations of #43.

  * Create 'Copyright' class.
  * Add 'Copyright' to 'File' object.
  * Add empty lists for 'copyrights' and 'licenses' fields to 'File.to_dict()'.
  * Add new tests, fix failing tests.

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
  * Add copyright_diff().
  * Refactor license_diff().
  * Add new tests and related test old/new scan pairs.

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
Signed-off-by: John M. Horan <johnmhoran@gmail.com>
Comment thread src/deltacode/__init__.py Outdated
i.score += 15
if delta.new_file.licenses == [] and len(delta.old_file.licenses) > 0:
delta.factors.append('license info removed')
delta.score += 15

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make a method that down

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turn this logic into a function where you pass a score and a string. Then we can replace lines like 207 and 208 with a single function call instead of two line tweaks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for this as well

Comment thread src/deltacode/__init__.py
if delta.new_file.copyrights == [] and len(delta.old_file.copyrights) > 0:
delta.factors.append('copyright info removed')
delta.score += 10
return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best that we score these the same. This will also allow for you to combine the logic into a single if statement

Comment thread src/deltacode/__init__.py Outdated

if ((new_statements != old_statements) or
(new_holders != old_holders) or
(new_authors != old_authors)):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should ignore looking at copyright authors for now unless we have a good reason to use them.

Also I believe we need to rely more on holders. This needs some thought though

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaJuRG I've made this change -- let me know when you'd like to discuss how we could place greater reliance on holders.

Comment thread src/deltacode/models.py
self.statements = dictionary.get('statements')
self.holders = dictionary.get('holders')
self.authors = dictionary.get('authors')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I mentioned above, lets remove authors.

Comment thread src/deltacode/models.py
'file' dictionary.
"""
def __init__(self, dictionary={}):
self.statements = dictionary.get('statements')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you haven’t already, you should add tests cases where a files have large numbers of copyrights holders and statements to see if we choke somewhere, espically in the output

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also tests where there are strange characters or accent marks in the copyright statements/holders.

All of these additional test cases I mentioned should probably come from scancode generated output directly as opposed to crafting the test object by hand.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaJuRG Since we want to use ScanCode-generated output, do you have any codebases in mind that satisfy the characteristics you describe?

I've started to work my way through the codebases we've worked with (openssl, zlib et al.) but I've not yet seen large numbers of copyright holders/statements or unusual characters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnmhoran You will probably just have to hand-create a file or files that contain a bunch of copyright statements

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Thanks, @MaJuRG .

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaJuRG I'm finding that an error is thrown when I include a French accent character in the copyright statements or holders value, e.g., "é". The error is thrown even if I comment out the character (presumably because even comments are parsed). Unicode and UTF-8 do not throw an error.

...
"statements": [
    "U+00E9",
    "\xc3\xa9"
    # "é"
...

SyntaxError: Non-ASCII character '\xc3' in file C:\code\nexb\dev\deltacode\tests\test_models.py on line 1073, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

While PEP 263 gives some suggestions, it's not clear to me how we can apply these to handle our input. I've done some searching in the ScanCode repo -- surely ScanCode must be able to handle such characters -- but have not yet found how ScanCode addresses this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this issue might be addressed in scancode-toolkit/src/commoncode/text.py?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnmhoran where is this "statements" located?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaJuRG Per your suggestion above, I'm hand-crafting old and new files in a new test, test_Copyright_unusual_characters(), in test_models.py.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaJuRG Would it be easier for you if I commit and push? Except for this one failing test, it's ready for your review.

  * Add scoring method to Delta -- Delta.add_score().
  * Call new scoring method from DeltaCode.license_diff() and
    DeltaCode.copyright_diff().
  * Add tests for Delta.add_score().
  * Modify score for 'copyright info added'.
  * Remove references to copyright authors.
  * Add tests cases where a files have large numbers of copyright
    holders and statements.
  * Add tests cases where a files have unusual characters -- but errors
    thrown with French accent characters.

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
Comment thread src/deltacode/__init__.py Outdated
if len(delta.new_file.licenses) > 0 and delta.old_file.licenses == []:
delta.factors.append('license info added')
delta.score += 20
delta.add_score(20, 'license info added')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be renamed to something like delta.update.
We are not only adding to the score, we are also adding to factors etc and possibly more in the future.

Comment thread src/deltacode/__init__.py Outdated
def add_score(self, score=0, factor=''):
"""
For each Delta object identified in DeltaCode.license_diff() or
DeltaCode.copyright_diff(), add the score to the object's 'score'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need ot mention these funtions here. Simply tell me what this update function does.

Comment thread src/deltacode/__init__.py Outdated
self.factors = []
self.score = score

def add_score(self, score=0, factor=''):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like stated above, this needs to be renamed to update.

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
@johnmhoran

Copy link
Copy Markdown
Member Author

@MaJuRG Done except for the question of how to test unusual characters like the French é in copyright statements/holders. How shall we handle that testing?

@steven-esser

Copy link
Copy Markdown
Contributor

@johnmhoran I do not know the best way.

Have you:

  1. created some file with copyright statement that has that accent?
  2. scan that file with scancode using -clip option
  3. placed that result scanfile in the data direcoty to be used as a test case?
  4. run the test?

I ask because I dont really have a context to the error above and therefore cannot point you in the right direction.

@steven-esser

Copy link
Copy Markdown
Contributor

For example, scancode results may handle things like this implicitly, and we do not need to worry about it. OR it could be that we need to sanitize these strings at some point along the line depending on what operations we are performing.

Unfortunately, this is a side effect of python2 specific problems w.r.t strings and character encodings.

It may be that we push that particular issue off in favor of python3 migration, but we need more details. We may not care at all.

More research on your part is always something you can do as well; I will not be able to really provide specific code examples etc until late weds or thurs

@johnmhoran

Copy link
Copy Markdown
Member Author

@MaJuRG Understood. I did a fair amount of research but couldn't figure out how to apply it to the DeltaCode/ScanCode context. However, thinking about the process, I expect that my prior approach -- hand-crafting the input inside the test itself -- meant that any existing ScanCode/commoncode remediation was not encountered by the input.

I like your suggestion -- will create separate files, scan with ScanCode and use for testing.

  * Added scans and tests for unusual characters like French and German
    letters with accent marks.

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
@johnmhoran

Copy link
Copy Markdown
Member Author

@MaJuRG Working on issue #71 branched from my branch for issue #83, I noticed two print statements in the test test_Delta_to_dict_Copyright_unusual_characters() and have removed them.

Signed-off-by: John M. Horan <johnmhoran@gmail.com>
@steven-esser
steven-esser merged commit 5459956 into develop Mar 8, 2018
@steven-esser
steven-esser deleted the 83-add-copyright-diff branch March 23, 2018 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants